import 'package:flutter/material.dart';

class BadgeIcon extends StatelessWidget {
  final String imagePath; // 图片路径
  final bool isNetwork;   // 是否是网络图片
  final bool showBadge;
  final int? badgeCount;
  final double size;
  final VoidCallback? onPressed;
  
  const BadgeIcon({
    super.key,
    required this.imagePath,
    this.isNetwork = false,
    this.showBadge = false,
    this.badgeCount,
    this.size = 24,
    this.onPressed,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onPressed,
      child: Stack(
        clipBehavior: Clip.none,
        children: [
          _buildImage(),
          if (showBadge) _buildBadge(),
        ],
      ),
    );
  }

  Widget _buildImage() {
    return isNetwork
        ? Image.network(
            imagePath,
            width: size,
            height: size,
            fit: BoxFit.contain,
          )
        : Image.asset(
            imagePath,
            width: size,
            height: size,
            fit: BoxFit.contain,
          );
  }

  Positioned _buildBadge() {
    return Positioned(
      right: 0,
      top: -4,
      child: Container(
        padding: const EdgeInsets.all(3),
        decoration: const BoxDecoration(
          color: Colors.red,
          shape: BoxShape.circle,
        ),
        child: Text(
          badgeCount?.toString() ?? '',
          style: const TextStyle(color: Colors.white, fontSize: 10),
        ),
      ),
    );
  }
}
